﻿Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        esegui("A", "Z")
    End Sub

    Private Sub A_Click(sender As Object, e As EventArgs) Handles A.Click
        esegui("A", "G")
    End Sub

    Private Sub B_Click(sender As Object, e As EventArgs) Handles B.Click
        esegui("H", "P")
    End Sub

    Private Sub C_Click(sender As Object, e As EventArgs) Handles C.Click
        esegui("Q", "Z")
    End Sub

    Private Sub esegui(
    ByVal daLettera As String,
    ByVal aLettera As String)
        Dim db As NorthWindEntities =
           New NorthWindEntities()
        Dim contatti =
          From c In db.Clienti
          Where c.Nome.Substring(0, 1) >=
            daLettera And
            c.Nome.Substring(0, 1) <=
            aLettera
          Order By c.Nome, c.Cognome
          Select c.Nome, c.Cognome
        Me.DataGridView1.DataSource = contatti
    End Sub
End Class
